package cn.acewill.yxd.yunxundian.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import java.util.List;

import cn.acewill.yxd.yunxundian.R;
import cn.acewill.yxd.yunxundian.model.wentifenxiBean;

/**
 * Created by XXX on 2017/6/1.
 */

public class QuestionAdapter extends BaseAdapter{

    private Context context;
    private List<wentifenxiBean> list;
    private onClickCallBack callBack;


    public QuestionAdapter(Context context, List<wentifenxiBean> list, onClickCallBack callBack){
        this.context=context;
        this.list=list;
        this.callBack=callBack;

    }
    @Override
    public int getCount() {
        return list==null?0:list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if (convertView==null){
            convertView= LayoutInflater.from(context).inflate(R.layout.question_info,parent,false);
            holder=new ViewHolder();
            holder.deleteTask= (ImageView) convertView.findViewById(R.id.deleteTask);
            holder.taskCode= (TextView) convertView.findViewById(R.id.taskCode);
            holder.taskDesc= (TextView) convertView.findViewById(R.id.taskDesc);
            convertView.setTag(holder);
        }else{
            holder= (ViewHolder) convertView.getTag();
        }
        wentifenxiBean test=list.get(position);

        String title=test.getTitlestr().replaceAll(",","\t");
        holder.taskCode.setText(title);
        holder.taskDesc.setText(test.getCommonstr());
        holder.deleteTask.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                callBack.deleteQuest(position);
            }
        });

        return convertView;
    }

    class ViewHolder{
        TextView taskCode;
        TextView taskDesc;
        ImageView deleteTask;
    }

    public interface onClickCallBack{
        void deleteQuest(int position);
    }

}
